import { EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RoundInfo, RecmInfo } from "../ExecutePlan";
import { IRecmStrategy } from "../IRecmStrategy";

export class BossRecmItem {
    recmArray: EnumBjlResult[] = [];
    result: EnumBjlResult = EnumBjlResult.U;
    /**
    * 0:正常兔子
    * 1:快一步兔子
    * 2:保守兔子
    * 3:阶梯兔子
    * 4:平推兔子
    * 5:固定兔子
    */
    rabbitType: string = "0";
    /**
     * 保守兔子的时候上线倍数
     */
    extendMultiple: number = 0;
}




export interface BossRecmOption {
    recmItem: BossRecmItem[];
}

export class BossRecmStrategy implements IRecmStrategy {
    graphicArray: BossRecmItem[] = [];
    constructor(name: string, option?: BossRecmOption) {
        this.strategyName = name;
        if (option) {
            this.graphicArray = option.recmItem;
        }
        else {
            this.graphicArray = [];
        }

    }
    setResult(roundInfo: RoundInfo, recmInfo: RecmInfo, multiple: number, waterRate: number, fuliRate: number): void {
        return;
    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        var strResult = roundInfo.results.join('');
        var recmItem = this.graphicArray.filter(it => strResult.endsWith(it.recmArray?.join('')??""));
        let iv = 0;
        for (let i = 0; i < recmItem.length; i++) {
            if (recmItem[i].result == EnumBjlResult.Z) {
                iv++;
            }
            else if (recmItem[i].result == EnumBjlResult.X) {
                iv--;
            }
        }
        if (iv > 0) {
            return EnumBjlResult.Z;
        }
        else if (iv < 0) {
            return EnumBjlResult.X;
        }
        return EnumBjlResult.U;
    }
    strategyName: string = '';
    debugCompoenent: string = '';
    resetRecm(): void {

    }
    copyValue(valueObj: any): void {
        var obj = valueObj as BossRecmStrategy;
        if (obj) {
            this.graphicArray = obj.graphicArray;
        }
    }

    getRecm() {
        return this.graphicArray;
    }
    removeGraphic(idx: number) {
        this.graphicArray.splice(idx, 1);
    }
    addGraphic(item: BossRecmItem) {
        this.graphicArray.push(item);
    }
}